
#ifndef _IGJKPAIRDETECTOR_H_
#define _IGJKPAIRDETECTOR_H_

#include "IDetectorResult.h"
#include "IGjkEpaSolver.h"
#include "IVoronoiSimplexSolver.h"

inline bool FuzzyZero(BReal x)
{
	return fabs(x) < REAL_EPSILON;
}
inline bool FuzzyZero(const BVector& vec)
{
	return vec.length2() < REAL_EPSILON * REAL_EPSILON;
}

class IGjkPairDetector : public BThing
{
	BShape*			_shapeA;
	BShape*			_shapeB;
	BReal			_marginA;
	BReal			_marginB;
	BVector			_separatingAxis;
	IVoronoiSimplexSolver* _simplexSolver;

public:
	IGjkPairDetector(BShape* shapeA, BShape* shapeB, IVoronoiSimplexSolver* simplexSolver);

	virtual void closestPoints(const BMatrix& matrixA, const BMatrix& matrixB, IDetectorResult& output);

	void setCachedSeparatingAxis(const BVector& separatingAxis)
	{
		_separatingAxis = separatingAxis;
	}

	const BVector& getCachedSeparatingAxis() const
	{
		return _separatingAxis;
	}

	bool calcPenDepth(BShape* shapeA, BShape* shapeB, const BMatrix& matrixA, const BMatrix& matrixB, IGjkEpaSolver::Result& result);

};

#endif
